package com.sltx.config;

import com.google.common.base.Throwables;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class TencentSmsScript {
    private static final String URL = "sms.tencentcloudapi.com";
    private static final String REGION = "ap-nanjing";
    private final static String SECRET_ID = "AKID0oOzj18zlaOzMYZQ3ScbMuFKKWXWK2Xx";
    private final static String SECRET_KEY = "KSN6czB9uUBh184nLhqqdEerumV6Wikd";
    private static final String SMS_SDK_APP_ID = "1400499107";
    private static final String TEMPLATE_ID = "1556817";
    private static final String SIGN_NAME = "数联天下";
    public String send(String Phone,String Content) {
        try {
            Credential cred = new Credential(SECRET_ID, SECRET_KEY);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(URL);
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, REGION, clientProfile);
            SendSmsRequest req = new SendSmsRequest();
            String[] phoneNumberSet1 = {Phone};
            req.setPhoneNumberSet(phoneNumberSet1);
            req.setSmsSdkAppid(SMS_SDK_APP_ID);
            req.setSign(SIGN_NAME);
            req.setTemplateID(TEMPLATE_ID);
            String[] templateParamSet1 = {Content};
            req.setTemplateParamSet(templateParamSet1);
            SendSmsResponse resp = client.SendSms(req);
            return SendSmsResponse.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            log.error("send tencent sms fail!{},params:{}", Throwables.getStackTraceAsString(e));
            return null;
        }

    }
}
